//2009/09/10 06:04:33
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class TheCardShufflingDivTwo
{
public:
    int shuffle(int n, int m)
    {
        vector<int> main;
        vector<int> left;
        vector<int> right;
        for (int i=0; i<n; i++) main.push_back(i+1);
        //for (int i=0; i<n; i++) cout << main[i] << ", ";
        //cout << endl;
		reverse(main.begin(), main.end());
        for (int i=1; i<=m; i++)
        {
            for (int j=main.size()-1; j>=0; j-=2)
                left.push_back(main[j]);
            //for (int j=0; j<left.size(); j++)
            //    cout << left[j] << ", ";
            cout << endl;
            for (int j=main.size()-2; j>=0; j-=2) right.push_back(main[j]);
            main.clear();
            for (int j=left.size()-1; j>=0; j--) main.push_back(left[j]);
            left.clear();
            for (int j=right.size()-1; j>=0; j--) main.push_back(right[j]);
            right.clear();
        }
        return main[main.size()-1];
    }
};
